cssvalue: Add a GtkCssValue for idents
authorBenjamin Otte <otte@redhat.com>
Tue, 17 Apr 2012 05:46:17 +0000 (07:46 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 17 Apr 2012 06:59:16 +0000 (08:59 +0200)
gtk/gtkcssstringvalue.c
gtk/gtkcssstringvalueprivate.h

index aaa3ebb3d45855955c9988a6ce645092efc94ef0..ec58ed99a68ece219097607af1f94a76ec0042c6 100644 (file)
@@ -88,6 +88,46 @@ gtk_css_value_string_print (const GtkCssValue *value,
   g_string_append_c (str, '"');
 }
 
+static void
+gtk_css_value_ident_print (const GtkCssValue *value,
+                            GString           *str)
+{
+  char *string = value->string;
+  gsize len;
+
+  do {
+    len = strcspn (string, "\"\n\r\f");
+    g_string_append_len (str, string, len);
+    string += len;
+    switch (*string)
+      {
+      case '\0':
+        break;
+      case '\n':
+        g_string_append (str, "\\A ");
+        break;
+      case '\r':
+        g_string_append (str, "\\D ");
+        break;
+      case '\f':
+        g_string_append (str, "\\C ");
+        break;
+      case '\"':
+        g_string_append (str, "\\\"");
+        break;
+      case '\'':
+        g_string_append (str, "\\'");
+        break;
+      case '\\':
+        g_string_append (str, "\\\\");
+        break;
+      default:
+        g_assert_not_reached ();
+        break;
+      }
+  } while (*string);
+}
+
 static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
   gtk_css_value_string_free,
   gtk_css_value_string_equal,
@@ -95,6 +135,13 @@ static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
   gtk_css_value_string_print
 };
 
+static const GtkCssValueClass GTK_CSS_VALUE_IDENT = {
+  gtk_css_value_string_free,
+  gtk_css_value_string_equal,
+  gtk_css_value_string_transition,
+  gtk_css_value_ident_print
+};
+
 GtkCssValue *
 _gtk_css_string_value_new (const char *string)
 {
@@ -135,3 +182,43 @@ _gtk_css_string_value_get (const GtkCssValue *value)
   return value->string;
 }
 
+GtkCssValue *
+_gtk_css_ident_value_new (const char *ident)
+{
+  return _gtk_css_ident_value_new_take (g_strdup (ident));
+}
+
+GtkCssValue *
+_gtk_css_ident_value_new_take (char *ident)
+{
+  GtkCssValue *result;
+
+  result = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_IDENT);
+  result->string = ident;
+
+  return result;
+}
+
+GtkCssValue *
+_gtk_css_ident_value_try_parse (GtkCssParser *parser)
+{
+  char *ident;
+
+  g_return_val_if_fail (parser != NULL, NULL);
+
+  ident = _gtk_css_parser_try_ident (parser, TRUE);
+  if (ident == NULL)
+    return NULL;
+  
+  return _gtk_css_ident_value_new_take (ident);
+}
+
+const char *
+_gtk_css_ident_value_get (const GtkCssValue *value)
+{
+  g_return_val_if_fail (value != NULL, NULL);
+  g_return_val_if_fail (value->class == &GTK_CSS_VALUE_IDENT, NULL);
+
+  return value->string;
+}
+
index 5338f02e0d7689067c5ba1a62851ba49f949686f..5fb703b6e3b5f8f5b38df01cb5b2134dd6391e2a 100644 (file)
 
 G_BEGIN_DECLS
 
+GtkCssValue *   _gtk_css_ident_value_new            (const char             *ident);
+GtkCssValue *   _gtk_css_ident_value_new_take       (char                   *ident);
+GtkCssValue *   _gtk_css_ident_value_try_parse      (GtkCssParser           *parser);
+
+const char *    _gtk_css_ident_value_get            (const GtkCssValue      *ident);
+
 GtkCssValue *   _gtk_css_string_value_new           (const char             *string);
 GtkCssValue *   _gtk_css_string_value_new_take      (char                   *string);
 GtkCssValue *   _gtk_css_string_value_parse         (GtkCssParser           *parser);